using System;
using System.Collections.Generic;
using System.Runtime.Remoting;
using System.Text;
using System.Threading;
using Sedna.API;
using Sedna.API.Security;
using Sedna.API.Support;
using Sedna.Core.Support;

namespace Sedna.API.Security
{
    public class UserContext: IUserContext   
    {
        private ISecurityAPI securityAPI;
        private IToken currentSessionKey;
        private string username;
        private string password;

        public string Username
        {
            get { return username; }
            set { username = value; }
        }

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        public IToken CurrentSessionKey
        {
            get { return currentSessionKey; }
            set { currentSessionKey = value; }
        }

        public ISecurityAPI SecurityAPI
        {
            set { securityAPI = value; }
        }

        public void Login(string uname, string pass)
        {
            Assert.IsNotEmptyString(uname, "User name cannot be empty");
            Assert.IsNotEmptyString(pass, "Password cannot be empty");
            CurrentSessionKey = securityAPI.Login(uname, pass);
        }        
                
        public void Login()
        {
            Login(username, password);
        }
                
        public void Logout()
        {
            securityAPI.Logout(CurrentSessionKey);
            CurrentSessionKey = null;
        }

    }
}

